/*
    Created by IntelliJ IDEA.
    @Auther: gaozhe
    @Date: 2020/1/19 上午 10:22
    
*/
package com.gaozhe.controller;

import com.gaozhe.pojo.Books;
import com.gaozhe.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/book")
public class BookController {
    @Autowired
    @Qualifier("bookServiceImpl")
    private BookService bookService;
    @RequestMapping("/allBook")
    public String allBook(Model model){
        System.out.println("进入queryAllBook");
        List<Books> allBook = bookService.queryAllBook();
        System.out.println(allBook);
        model.addAttribute("allBook",allBook);
        return "allBook";
    }
    @RequestMapping("/toAddBook")
    public String add(){
        return "addBook";
    }
    @RequestMapping("/addBook")
    public String addBook(Books books){
        int i = bookService.addBook(books);
        return "redirect:/book/allBook";
    }
    @RequestMapping("/toUpdateBook")
    public String update(int id,Model model){
        Books books = bookService.queryBookById(id);
        model.addAttribute("books",books);
        return "updateBook";
    }
    @RequestMapping("/updateBook")
    public String updateBook(Books books){
        int i = bookService.updateBook(books);
        return "redirect:/book/allBook";
    }
    @RequestMapping("/del/{id}")
    public String deleteBook(@PathVariable("id") int id){
        int i = bookService.deleteBookById(id);
        return "redirect:/book/allBook";
    }




}
